<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RegistRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        //如果需要使用表单验证类来完成表单验证 需要将返回值fales改为true
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'=>'required',
            'email'=>'required|email',
            'password'=>'required|between:6,16|confirmed',//手册中查看confirmed
            'password_confirmation'=>'required|between:6,16'
        ];
    }
    //如果想将错误提示改为中文可以在表单验证类中重写messages方法
    public function messages(){
        //格式是a=>b, a写的是被验证的字段名.验证规则，b写的是错误提示
        return[
           'name.required'=>'你没写用户名',
           'email.required' => '邮箱没写',
           'password.required' => '兄die,密码不能为空',
           'password.between' => '哥们,密码长度不支持',
           'password.confirmed' => '兄die,两次密码输入不一致!!!',
           'password_confirmation.required' => '确认密码不能为空',
           'password_confirmation.between' => '确认密码长度不支持',
            ];
    }

}
